//
//  ChartController.m
//  GuoBang
//
//  Created by 梧桐树 on 16/4/27.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "ChartController.h"

@interface ChartController ()
{
    
    KaFeiStelyTableViewCell *kafeiCell;
    UIButton *riLiBtn;
    UIButton *biaoBtn;
    __weak IBOutlet UITextField *SpecifiedTime;
    UUDatePicker *mydatePicker;
    UUDatePicker *daChedatePicker;
    
    
    UIButton *cancleBtn;
    UIButton *deteminBtn;
    UIView *shijianView;
    
    
    // 定咖啡的总杯数和总钱数
    UILabel *beiNum;
    UILabel *yuanNum;
    
    // 用车时间的按钮
    UIButton *yongcheTime;
    
    // 只是为了打开关闭
    NSMutableArray *openArr;
    
    
    
    NSArray *zhongleiArr;
    NSArray *nameArr;
    
    
    NSMutableArray *kafeiArr;
    
    // 杯数
    NSInteger beishu;
    NSInteger yuanshu;
    
    
    
}

@property (nonatomic, strong) UIView *coverView;
@property (nonatomic, strong) UIView *promptView;
@property (nonatomic, strong) UILabel *placeHoldLabel;

// 第二个遮盖
@property (nonatomic, strong) UIView *coverView1;
@property(nonatomic,strong)ZHPickView *pickview;




// 特殊的遮罩
@property (nonatomic, strong) UIView *daCheprompView;


@end

@implementation ChartController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNav];
    [self setData];
    [self setUI];
    
}
-(void)setUI{
    
    
    
    
   
    zhongleiArr = @[@"热咖啡",@"冰咖啡",@"巧克力"];
    //hearderHi(详见h文件)
    hearderHi=20;
    tab=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-48) style:UITableViewStyleGrouped];
    tab.delegate=self;
    tab.dataSource=self;
    [self.view addSubview:tab];
    //隐藏分隔线
    tab.separatorStyle = UITableViewCellSeparatorStyleNone;
    //注册键盘监听
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardwillshow:) name:UIKeyboardWillShowNotification  object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self  selector:@selector(keyboardwillback:) name:UIKeyboardWillHideNotification object:nil];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tabend)];
    
    [tab.backgroundView addGestureRecognizer:tap];
    [tab addGestureRecognizer:tap];
    //添加键盘
    keyView=[[CustomKeyBoard alloc]initWithFrame:CGRectMake(0, HEIGHT-48, WIDTH, 48)];
    keyView.delegate=self;
    [self.view addSubview:keyView];
     [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(remove:) name:@"RemoveCoverView" object:nil];
    
    
    
    
    //录音设置
    NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
    //设置录音格式  AVFormatIDKey==kAudioFormatLinearPCM
    [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
    //设置录音采样率(Hz) 如：AVSampleRateKey==8000/44100/96000（影响音频的质量）, 采样率必须要设为11025才能使转化成mp3格式后不会失真
    [recordSetting setValue:[NSNumber numberWithFloat:11025.0] forKey:AVSampleRateKey];
    //录音通道数  1 或 2 ，要转换成mp3格式必须为双通道
    [recordSetting setValue:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
    //线性采样位数  8、16、24、32
    [recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    //录音的质量
    [recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];
    
    //存储录音文件
    recordUrl = [NSURL URLWithString:[NSTemporaryDirectory() stringByAppendingString:@"selfRecord.caf"]];
    
    //初始化
    audioRecorder = [[AVAudioRecorder alloc] initWithURL:recordUrl settings:recordSetting error:nil];
    //开启音量检测
    audioRecorder.meteringEnabled = YES;
    audioRecorder.delegate = self;

    
    images=[[UIImageView alloc]initWithFrame:CGRectMake((WIDTH-200)/2, HEIGHT/2+75, 200, 100)];
    images.image=[UIImage imageNamed:@"luyinLogo@2x.png"];
    images.hidden=YES;
 [self.view addSubview:images];
    
    
    
}
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

-(void)setNav{
    //设置标题
    self.title=@"小秘";
    //设置右侧nav按键
    UIButton* btn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
    [btn addTarget:self action:@selector(toGeRen) forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundImage:[UIImage imageNamed:@"ico_me@2x.png"] forState:UIControlStateNormal];
    UIBarButtonItem*rightItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    [self.navigationItem setRightBarButtonItem:rightItem];

}
-(void)setData{
    messageArry =[NSMutableArray new];
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *currentTime = [formatter stringFromDate:[NSDate date]];
    NSDictionary *dic1=@{@"date":currentTime,@"dataArry":@[]};
    [messageArry addObject:dic1];
}

//跳至个人中心
-(void)toGeRen{
    PersonController *per=[PersonController new];
    [self.navigationController pushViewController:per animated:YES];

}
-(void)tabend{
    if (keyView.functionIsShow==1) {
        [keyView functionHiden];
        
    }
    if (keyView.kbIsShow==1) {
        [keyView keyboardHiden];
    }
    if(keyView.emojiIsShow==1){
        [keyView emojiHiden];
        
    }
    [self.view endEditing:YES];

}
#pragma mark 键盘方法
//监听方法
-(void)keyboardwillshow:(NSNotification*)notification;
{
    //往上推屏幕的操作（field在屏幕下半部分时使用）
    //NSLog(@"%@",notification.userInfo);//键盘尺寸坐标；
    NSDictionary*a=[notification userInfo];
    CGRect rect=[[a objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
    CGFloat h=rect.size.height;
    //NSLog(@"%f",h);
    if (keyView.functionIsShow==1) {
        [keyView functionHiden];
        
    }
    if (keyView.kbIsShow==1) {
        [keyView keyboardHiden];
    }
    if(keyView.emojiIsShow==1){
        [keyView emojiHiden];
        
    }
    keyView.luyin.hidden=YES;
     [keyView.keyBoardTypeBtn setImage:[UIImage imageNamed:@"ico_add@2x.png"] forState:UIControlStateNormal];
    self.view.frame=CGRectMake(0, 0,WIDTH, HEIGHT-h);
 
    keyView.frame=CGRectMake(0, self.view.frame.size.height-keyView.frame.size.height, WIDTH, keyView.frame.size.height);
    tab.frame=CGRectMake(0, 0, WIDTH, HEIGHT-h-keyView.frame.size.height);
    
    
    
    
    
    
}
-(void)keyboardwillback:(NSNotification*)notification;
{
//    [keyView.keyBoardTypeBtn setImage:[UIImage imageNamed:@"Keyboard-64@2x.png"] forState:UIControlStateNormal];
    self.view.frame=CGRectMake(0, 0,WIDTH, HEIGHT);
    keyView.frame=CGRectMake(0, self.view.frame.size.height-keyView.frame.size.height, WIDTH, keyView.frame.size.height);
     tab.frame=CGRectMake(0, 0, WIDTH, HEIGHT-keyView.frame.size.height);
}
//点击空白区域回收键盘
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    
    [super touchesBegan:touches withEvent:event];
    [self.view endEditing:YES];
}
#pragma mark CustomKeybopardDelegate
-(void)emojiHidens{
    keyView.frame=CGRectMake(keyView.frame.origin.x,self.view.frame.size.height-48, keyView.frame.size.width,48);
    keyView.emojiIsShow=2;
    tab.frame=CGRectMake(0, 0, WIDTH, self.view.frame.size.height-keyView.frame.size.height);
}
-(void)changeTabFrame:(int)lineNum fontHeight:(int)fontHeight emojiHi:(int)emojiHi{
    keyView.frame=CGRectMake(keyView.frame.origin.x,self.view.frame.size.height-48-fontHeight*(lineNum-1)-emojiHi, keyView.frame.size.width,48+fontHeight*(lineNum-1)+emojiHi);
    tab.frame=CGRectMake(0, 0, WIDTH, self.view.frame.size.height-keyView.frame.size.height);
}
-(void)showFunction:(int)nowFun height:(int)height{
    
       
    tab.frame=CGRectMake(0, 0, WIDTH, self.view.frame.size.height-keyView.frame.size.height);
        
}
-(void)selectPhoto{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
   
    [self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)takePhoto{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
   
    [self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)sendMessage:(NSString *)message{

    NSLog(@"%@",message);
    
    NSDictionary *dicc1=@{@"message":message,@"type":@"string",@"from":@"user"};
    NSDictionary *dicc2;
    if ([[dicc1 objectForKey:@"message"]isEqualToString:@"我要充值话费！"]) {
        dicc2 =@{@"message":message,@"type":@"order",@"want":@"huafei",@"from":@"service",@"list":@[@"",@"",@"",@"",@"",@"",@"",@""]};
    }
    if ([[dicc1 objectForKey:@"message"]isEqualToString:@"我要喝咖啡！"]) {
        dicc2 =@{@"message":message,@"type":@"order",@"want":@"kafei",@"from":@"service",@"list":@[@"",@"",@"",@"",@"",@"",@"",@""]};
    }
    if ([[dicc1 objectForKey:@"message"]isEqualToString:@"我要打车！"]) {
        dicc2 =@{@"message":message,@"type":@"order",@"want":@"dache",@"from":@"service",@"list":@[@"",@"",@"",@"",@"",@"",@"",@""]};
    }
    if ([[dicc1 objectForKey:@"message"]isEqualToString:@"我要点下午茶！"]) {
        dicc2 =@{@"message":message,@"type":@"order",@"want":@"xiawucha",@"from":@"service",@"list":@[@"",@"",@"",@"",@"",@"",@"",@""]};
    }
    if ([[dicc1 objectForKey:@"message"]isEqualToString:@"我要吃零食！"]) {
        dicc2 =@{@"message":message,@"type":@"order",@"want":@"lingshi",@"from":@"service",@"list":@[@"",@"",@"",@"",@"",@"",@"",@""]};
    }
    if ([[dicc1 objectForKey:@"message"]isEqualToString:@"我要吃水果！"]) {
        dicc2 =@{@"message":message,@"type":@"order",@"want":@"shuiguo",@"from":@"service",@"list":@[@"",@"",@"",@"",@"",@"",@"",@""]};
    }
    if ([[dicc1 objectForKey:@"message"]isEqualToString:@"有没有更多服务？"]) {
        dicc2 =@{@"message":message,@"type":@"order",@"want":@"gengduo",@"from":@"service",@"list":@[@"",@"",@"",@"",@"",@"",@"",@""]};
    }
   
   NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithDictionary:[messageArry objectAtIndex:messageArry.count-1]];
    
    NSMutableArray *arr=[NSMutableArray arrayWithArray:[dic objectForKey:@"dataArry"]];
    [arr addObject:dicc1];
    if (dicc2) {
         [arr addObject:dicc2];
    }
   
    [dic setObject:arr forKey:@"dataArry"];
    [messageArry replaceObjectAtIndex:messageArry.count-1 withObject:dic];
    [tab reloadData];
    [tab scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:arr.count-1 inSection:messageArry.count-1] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    
    
    
}
#pragma mark imagePickerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; // 得到图片的缓存数据
    
   // [self performSelector:@selector(saveImage:)  withObject:image afterDelay:0.5];
    
   
        //==============
   // NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    //==============
    
    
    
    //上面的代码是当从相册里面选取图片之后保存到本地程序沙盒，在上面我们得到的图片中不能够得到图片名字，以及不清楚图片格式，所以这个时候我们需要将其转换成NSdata二进制存储，
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filePath = [document stringByAppendingPathComponent:@"photos"];
    
    NSData *data;
    if (![fileManager fileExistsAtPath:filePath]) {
        BOOL blCreateFolder= [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:NO attributes:nil error:NULL];
        if (blCreateFolder) {
            NSLog(@" folder success");
        }else {
            NSLog(@" folder fial");
        }
    }else {
        NSLog(@" 沙盒文件已经存在");
    }

    if (UIImagePNGRepresentation(image) == nil) {
        
        data = UIImageJPEGRepresentation(image, 1);
        
    } else {
    
        data = UIImagePNGRepresentation(image);
        
    }
   // UIImagePNGRepresentation转换PNG格式的图片为二进制，如果图片的格式为JPEG则返回nil；
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a=[dat timeIntervalSince1970]*1000;
    NSString *timeString = [NSString stringWithFormat:@"/%f.png",a];//转为字符型
    [fileManager createFileAtPath:[filePath stringByAppendingString:timeString] contents:data attributes:nil];//    将图片保存为PNG格式
    NSDictionary *dicc1=@{@"message":[filePath stringByAppendingString:timeString],@"type":@"photo",@"long":[NSString stringWithFormat:@"%d\"",rTime]};
    
    NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithDictionary:[messageArry objectAtIndex:messageArry.count-1]];
    
    NSMutableArray *arr=[NSMutableArray arrayWithArray:[dic objectForKey:@"dataArry"]];
    [arr addObject:dicc1];
    [dic setObject:arr forKey:@"dataArry"];
    [messageArry replaceObjectAtIndex:messageArry.count-1 withObject:dic];
    [tab reloadData];
    [tab scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:arr.count-1 inSection:messageArry.count-1] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
 
    [picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark TabView协议方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (tableView == self.kafeiTab) {
        
        NSString *str = openArr[section];
        if ([str isEqualToString:@"0"]) {
            return 0;
        }else{
    
        return 3;
        }
    }
    
    
    
    NSArray *arr=[[messageArry objectAtIndex:section] objectForKey:@"dataArry"];
       return arr.count;
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if (tableView == self.kafeiTab) {
        return 3;
    }
    
    return messageArry.count;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (tableView == self.kafeiTab) {
        return 40;
    }
    
    return hearderHi;
    
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (tableView == self.kafeiTab) {
        return 0.1;
    }
    
    return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (tableView == self.kafeiTab) {
       
        UIView *myhearderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 40)];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 13, 80, 14)];
        titleLabel.text = zhongleiArr[section];
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.textColor = RGBCOLOR(69, 69, 69);
        [myhearderView addSubview:titleLabel];
        
        
        UIButton *openBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        openBtn.frame = CGRectMake(WIDTH - 52, 0, 40, 40);
        
        openBtn.tag = section;
        NSString *str = openArr[section];
        if ([str isEqualToString:@"0"]) {
              [openBtn setImage:[UIImage imageNamed:@"ico_downarrow.png"] forState:UIControlStateNormal];
            [openBtn addTarget:self action:@selector(OpenAction:) forControlEvents:UIControlEventTouchUpInside];
            
        }else {
              [openBtn setImage:[UIImage imageNamed:@"ico_uparrow-.png"] forState:UIControlStateNormal];
             [openBtn addTarget:self action:@selector(CloseAction:) forControlEvents:UIControlEventTouchUpInside];
            
        }
        
        
        [myhearderView addSubview:openBtn];
        
        return myhearderView;
        
    }
    
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, hearderHi)] ;
    UILabel *time=[[UILabel alloc]initWithFrame:CGRectMake(0,5, WIDTH, 10)];
    time.textAlignment=NSTextAlignmentCenter;
    time.font=[UIFont systemFontOfSize:11];
    time.textColor=[SEATools stringToColor:@"909090"];
    time.text=[[messageArry objectAtIndex:section] objectForKey:@"date"];
    [headerView addSubview:time];
    [headerView setBackgroundColor:[SEATools stringToColor:@"efeff4"]];
    return headerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == self.kafeiTab) {
        return 160;
    }
    
    
    //根据CELL高度自动获取行高
    UITableViewCell *cell=[self tableView:tab cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    
    if (tableView == self.kafeiTab) {
        
        
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customcell"];
        
        
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"KaFeiStelyTableViewCell" owner:self options:nil];
        if (nib.count > 0) {
            kafeiCell = [nib objectAtIndex:0];
            
            
            
            NSArray *secArr = kafeiArr[indexPath.section];
            NSDictionary *dic = secArr[indexPath.row];
            kafeiCell.daNumLabel.text = [[dic objectForKey:@"num"] objectAtIndex:0];
            kafeiCell.zhongNumLabel.text = [[dic objectForKey:@"num"] objectAtIndex:1];
            kafeiCell.xiaoNumLabel.text = [[dic objectForKey:@"num"] objectAtIndex:2];
            
            kafeiCell.daPriceLabel.text = [[dic objectForKey:@"price"] objectAtIndex:0];
            kafeiCell.zhongPriceLabel.text = [[dic objectForKey:@"price"] objectAtIndex:1];
            kafeiCell.xiaoPriceLabel.text = [[dic objectForKey:@"price"] objectAtIndex:2];
            
            
            kafeiCell.daAddBtn.tag = indexPath.section * 100 + indexPath.row;
            kafeiCell.zhongAddBtn.tag = indexPath.section *100 + indexPath.row;
            kafeiCell.xiaoAddBtn.tag = indexPath.section *100 + indexPath.row;
            
            
            
            kafeiCell.daJianBtn.tag = indexPath.section *100 + indexPath.row;
            kafeiCell.zhongJianBtn.tag = indexPath.section *100 + indexPath.row;
            kafeiCell.xiaoJianBtn.tag = indexPath.section *100 + indexPath.row;
            
            
            [kafeiCell.daAddBtn addTarget:self action:@selector(addDa:) forControlEvents:UIControlEventTouchUpInside];
            [kafeiCell.zhongAddBtn addTarget:self action:@selector(addZhong:) forControlEvents:UIControlEventTouchUpInside];
            [kafeiCell.xiaoAddBtn addTarget:self action:@selector(addXiao:) forControlEvents:UIControlEventTouchUpInside];
            [kafeiCell.daJianBtn addTarget:self action:@selector(jianDa:) forControlEvents:UIControlEventTouchUpInside];
            [kafeiCell.zhongJianBtn addTarget:self action:@selector(jianZhong:) forControlEvents:UIControlEventTouchUpInside];
            [kafeiCell.xiaoJianBtn addTarget:self action:@selector(jianXiao:) forControlEvents:UIControlEventTouchUpInside];
            
            
            cell = kafeiCell;
            
        }
        cell.backgroundColor = [UIColor whiteColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        

        
    }
    
    
    
    MyMessageCell*cell=[tab dequeueReusableCellWithIdentifier:@"MyMessageCell"];
    OrderCell *cell2=[tab dequeueReusableCellWithIdentifier:@"OrderCell"];
  PlayVoiceCell *cell3=[tab dequeueReusableCellWithIdentifier:@"PlayVoiceCell"];
    
    if(cell==nil||cell2==nil)
    {
       
        if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"type"]isEqualToString:@"order"]) {
            NSArray *arr=[[NSBundle mainBundle]loadNibNamed:@"OrderCell" owner:nil options:nil];
            cell2=[arr objectAtIndex:0];

        }else  if([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"type"]isEqualToString:@"voice"]){
        
            NSArray *arr=[[NSBundle mainBundle]loadNibNamed:@"PlayVoiceCell" owner:nil options:nil];
            cell3=[arr objectAtIndex:0];
        }
        
        else{
            NSArray *arr=[[NSBundle mainBundle]loadNibNamed:@"MyMessageCell" owner:nil options:nil];
            cell=[arr objectAtIndex:0];
        }
        
    }
    
    
    if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"type"]isEqualToString:@"order"]) {
        
        if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"want"]isEqualToString:@"huafei"]) {
            cell2.title=@"话费";
            cell2.icon=@"ico_search_1@2x.png";
            cell2.dataArry=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"list"];
            cell2.style=Huafei   ;
        }
        if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"want"]isEqualToString:@"kafei"]) {
            cell2.title=@"咖啡";
            cell2.icon=@"ico_search_1@2x.png";
            cell2.dataArry=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"list"];
            cell2.style=Kafei  ;
            cell2.myDelegate = self;
            
        }

        if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"want"]isEqualToString:@"dache"]) {
            cell2.title=@"打车";
            cell2.addHiden=2;
            cell2.icon=@"ico_search_1@2x.png";
            cell2.dataArry=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"list"];
            cell2.style=Dache ;
            cell2.myDelegate = self;
        }

        if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"want"]isEqualToString:@"xiawucha"]) {
            cell2.title=@"下午茶";
            cell2.icon=@"ico_search_1@2x.png";
            cell2.dataArry=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"list"];
            cell2.style=Xiawucha ;
        }

        if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"want"]isEqualToString:@"lingshi"]) {
            cell2.title=@"零食";
            cell2.icon=@"ico_search_1@2x.png";
            cell2.dataArry=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"list"];
            cell2.style=Lingshi  ;
        }

        if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"want"]isEqualToString:@"shuiguo"]) {
            cell2.title=@"水果";
            cell2.icon=@"ico_search_1@2x.png";
            cell2.dataArry=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"list"];
            cell2.style=Shuiguo  ;
        }

        if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"want"]isEqualToString:@"gengduo"]) {
            cell2.title=@"更多";
            cell2.icon=@"ico_search_1@2x.png";
            cell2.dataArry=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"list"];
            cell2.style=Gengduo  ;
        }

        
            [cell2 loadCell];
        cell2.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell2;
        
        
    }else  if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"type"]isEqualToString:@"voice"]){
        //@{@"message":audioFileSavePath,@"type":@"voice",@"long":[NSString stringWithFormat:@"%d\"",rTime]};
        cell3.lab.text=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"long"];
        cell3.btn.tag=indexPath.section;
        cell3.btn.titleLabel.text=[NSString stringWithFormat:@"%ld",indexPath.row];
        [cell3.btn addTarget:self action:@selector(playVoice:) forControlEvents:UIControlEventTouchUpInside];
        cell3.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell3;
    
    }else  if ([[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"type"]isEqualToString:@"photo"]){
        //@{@"message":audioFileSavePath,@"type":@"voice",@"long":[NSString stringWithFormat:@"%d\"",rTime]};
        cell.messageStr=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row]objectForKey:@"message"];
        cell.delegate=self;
        [cell loadPhoto];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }
    else{
        //Cell赋值
        NSArray *arry=[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"];
        
        if (arry.count!=0) {
            if ([[[arry objectAtIndex:indexPath.row] objectForKey:@"from"]isEqualToString:@"user"]) {
                cell.messageStr=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"message"];
                [cell loadCell];
                
            }else{
                
                cell.messageStr=[[[[messageArry objectAtIndex:indexPath.section]objectForKey:@"dataArry"]objectAtIndex:indexPath.row] objectForKey:@"message"];
                
                [cell loadServiceCell];
                
            }
        }
        
        
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    

       return cell;
    
    
    
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == self.kafeiTab) {
       
        
        
        
    }else {
        
        
        //关闭选定高光效果
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
        if (keyView.functionIsShow==1) {
            [keyView functionHiden];
            
        }
        if (keyView.kbIsShow==1) {
            [keyView keyboardHiden];
        }
        if(keyView.emojiIsShow==1){
            [keyView emojiHiden];
            
        }
        [self.view endEditing:YES];

        
        
    }
    
    
}



-(void)showMePhoto:(UIImage *)image{
    PicDeViewController *pi=[PicDeViewController new];
    pi.photo=image;
    [self.navigationController pushViewController:pi animated:YES];

}


// 咖啡界面的打开和关闭
- (void)OpenAction:(UIButton *)sender
{
    [openArr replaceObjectAtIndex:sender.tag withObject:@"1"];
    
    [self.kafeiTab reloadData];
    
}



- (void)CloseAction:(UIButton *)sender
{
    
    [openArr replaceObjectAtIndex:sender.tag withObject:@"0"];
    
    [self.kafeiTab reloadData];
    
    
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)tixingAction
{
    
    
    [self addBottomViews];
}





- (void)addBottomViews
{
    self.coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.coverView.backgroundColor = [UIColor clearColor];
    [[UIApplication sharedApplication].keyWindow addSubview:self.coverView];
    UIView *alphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.coverView.frame.size.width, self.coverView.frame.size.height)];
    alphaView.backgroundColor = [UIColor blackColor];
    alphaView.alpha = 0.4;
    [self.coverView addSubview:alphaView];
    
    self.promptView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT / 3, WIDTH, HEIGHT / 3 * 2)];;
    self.promptView.backgroundColor = RGBCOLOR(255.0, 255.0, 255.0);
    //    self.promptView.layer.cornerRadius = 5;
    //    self.promptView.layer.masksToBounds = YES;
    [self.coverView addSubview:self.promptView];
    
    
    UIView *fBGView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 42)];
    fBGView.backgroundColor = RGBCOLOR(246, 248, 250);
    [self.promptView addSubview:fBGView];
    
    UILabel *tixingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 14, 70, 14)];
    tixingLabel.text = @"提醒设置";
    tixingLabel.font = [UIFont systemFontOfSize:14];
    tixingLabel.textColor = RGBCOLOR(32, 32, 32);
    [fBGView addSubview:tixingLabel];
    
    UIButton *quedingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quedingBtn.frame = CGRectMake(WIDTH - 60, 14, 60, 14);
    [quedingBtn setTitle:@"确定" forState:UIControlStateNormal];
    [quedingBtn setTitleColor:RGBCOLOR(255, 109, 109) forState:UIControlStateNormal];
    quedingBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [quedingBtn addTarget:self action:@selector(quedingAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [fBGView addSubview:quedingBtn];
    
    
    UIButton *quxiaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quxiaoBtn.frame = CGRectMake(WIDTH - 120, 14, 60, 14);
    [quxiaoBtn setTitle:@"取消" forState:UIControlStateNormal];
    [quxiaoBtn setTitleColor:RGBCOLOR(144, 144, 144) forState:UIControlStateNormal];
    quxiaoBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [quxiaoBtn addTarget:self action:@selector(quxiaoAction:) forControlEvents:UIControlEventTouchUpInside];
    [fBGView addSubview:quxiaoBtn];
    
    
    UITextView *tixingView = [[UITextView alloc]initWithFrame:CGRectMake(32, CGRectGetMaxY(fBGView.frame) + 14, WIDTH - 64, 47)];
    tixingView.delegate = self;
    [self.promptView addSubview:tixingView];
    
    
    self.placeHoldLabel = [[UILabel alloc] initWithFrame:CGRectMake(33, CGRectGetMaxY(fBGView.frame) + 14, WIDTH, 12)];
    
    self.placeHoldLabel.textColor = RGBCOLOR(152, 152, 152);
    
    self.placeHoldLabel.text = @"请输入需要提醒的事项";
    self.placeHoldLabel.font = [UIFont systemFontOfSize:12];
    
    [self.promptView addSubview:self.placeHoldLabel];
    
    UIView *seBGview = [[UIView alloc] initWithFrame:CGRectMake(16, CGRectGetMaxY(tixingView.frame) + 1, WIDTH - 32, 16)];
    
    seBGview.backgroundColor = RGBCOLOR(246, 248, 250);
    [self.promptView addSubview:seBGview];
    
    UILabel *tixingTime = [[UILabel alloc] initWithFrame:CGRectMake(16, 3, 60, 10)];
    
    tixingTime.font = [UIFont systemFontOfSize:10];
    tixingTime.text = @"提醒时间";
    tixingTime.textColor = RGBCOLOR(128, 128, 128);
    [seBGview addSubview:tixingTime];
    
    UIImageView *riliImageV = [[UIImageView alloc] initWithFrame:CGRectMake(31, CGRectGetMaxY(seBGview.frame) + 8, 15, 15)];
    riliImageV.image = [UIImage imageNamed:@"tx_ico_rl.png"];
    [self.promptView addSubview:riliImageV];
    
    riLiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    riLiBtn.frame = CGRectMake(CGRectGetMaxX(riliImageV.frame) + 11, CGRectGetMaxY(seBGview.frame) + 8, 100, 15) ;
    riLiBtn.titleLabel.font = [UIFont systemFontOfSize:10];
    [riLiBtn addTarget:self action:@selector(biaoAction:) forControlEvents:UIControlEventTouchUpInside];
    [riLiBtn setTitleColor:RGBCOLOR(50, 50, 50) forState:UIControlStateNormal];
     [riLiBtn setTitle:@"请选择时间" forState:UIControlStateNormal];
    [self.promptView addSubview:riLiBtn];
    
    UIImageView *topLine= [[UIImageView alloc] initWithFrame:CGRectMake(31, CGRectGetMaxY(riliImageV.frame) + 8, WIDTH - 62, 1)];
    
    topLine.backgroundColor = RGBCOLOR(204, 212, 222);
    [self.promptView addSubview:topLine];
    
    
    UIImageView *biaoImageV = [[UIImageView alloc] initWithFrame:CGRectMake(31, CGRectGetMaxY(topLine.frame) + 8, 15, 15)];
    biaoImageV.image = [UIImage imageNamed:@"tx_ico_sj.png"];
    [self.promptView addSubview:biaoImageV];
    
    
    biaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    biaoBtn.frame = CGRectMake(CGRectGetMaxX(biaoImageV.frame) + 11, CGRectGetMaxY(topLine.frame) + 8, 100, 15);
    biaoBtn.titleLabel.font = [UIFont systemFontOfSize:10];
    [biaoBtn setTitle:@"请选择时间" forState:UIControlStateNormal];
    [biaoBtn setTitleColor:RGBCOLOR(50, 50, 50) forState:UIControlStateNormal];
    
    
    
    [biaoBtn addTarget:self action:@selector(biaoAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
    [self.promptView addSubview:biaoBtn];
    
    UIImageView *bottomLine = [[UIImageView alloc] initWithFrame:CGRectMake(31, CGRectGetMaxY(biaoImageV.frame) + 8, WIDTH - 62, 1)];
    
    bottomLine.backgroundColor = RGBCOLOR(204, 212, 222);
    [self.promptView addSubview:bottomLine];
    
    
    UIImageView *phoneImageV = [[UIImageView alloc] initWithFrame:CGRectMake(31, CGRectGetMaxY(bottomLine.frame) + 8, 15, 15)];
    phoneImageV.image = [UIImage imageNamed:@"tx_ico_sj_s.png"];
    [self.promptView addSubview:phoneImageV];
    
    
    UITextField *phoneTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(biaoImageV.frame) + 11, CGRectGetMaxY(bottomLine.frame) + 8, 200, 15)];
    phoneTF.placeholder = @"请输入手机号";
    [phoneTF setBorderStyle:UITextBorderStyleNone];
    phoneTF.font = [UIFont systemFontOfSize:10];
    phoneTF.delegate = self;
    
    [self.promptView addSubview:phoneTF];
    
    
    UIView *thBGView = [[UIView alloc] initWithFrame:CGRectMake(16, CGRectGetMaxY(phoneImageV.frame) + 8, WIDTH - 32, 16)];
    
    thBGView.backgroundColor = RGBCOLOR(246, 248, 250);
    [self.promptView addSubview:thBGView];
    
    UILabel *tixingStely = [[UILabel alloc] initWithFrame:CGRectMake(16, 3, 60, 10)];
    
    tixingStely.font = [UIFont systemFontOfSize:10];
    tixingStely.text = @"提醒方式";
    tixingStely.textColor = RGBCOLOR(128, 128, 128);
    [thBGView addSubview:tixingStely];
    
    
    
    
    
    
    
    
    
    
    
    self.menuItem = @[@"电话提醒", @"短信提醒"];
    self.control = [[UISegmentedControl alloc] initWithItems:self.menuItem];
    self.control.frame = CGRectMake(WIDTH / 2 - 93, CGRectGetMaxY(thBGView.frame) + 10, 186, 31);
    self.control.backgroundColor = RGBCOLOR(244, 244, 244);
    self.control.tintColor =RGBCOLOR(255, 109, 109);
    self.control.selectedSegmentIndex = 0;
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12],
                                             NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]};
    [self.control setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];
    //设置文字属性
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12],
                                               NSForegroundColorAttributeName: [UIColor blackColor]};
    [self.control setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    [self.control addTarget:self action:@selector(selectedSegment:) forControlEvents:UIControlEventValueChanged];
    [self.promptView addSubview:self.control];
    
    
}


-(UISegmentedControl *)control
{
    if (!_control) {
        self.control = [[UISegmentedControl alloc] initWithItems:_menuItem];
        self.control.backgroundColor = RGBCOLOR(244, 244, 249);
//        self.control.tintColor =[UIColor clearColor];
        self.control.selectedSegmentIndex = 0;
        [self.control addTarget:self action:@selector(selectedSegment:) forControlEvents:UIControlEventValueChanged];
    }
    return _control;
}


- (void)selectedSegment:(UISegmentedControl *)sender
{
    NSInteger i = sender.selectedSegmentIndex;
    switch (i) {
        case 0:
        {
            NSLog(@"%ld", (long)i);
        }
            break;
        case 1:
        {
            NSLog(@"%ld", (long)i);
        }
            break;
        default:
            break;
    }
    
}






// 提醒取消
- (void)quxiaoAction:(UIButton *)sender
{
    
    [self.coverView removeFromSuperview];
    
    
    
}

// 提醒确定
- (void)quedingAction:(UIButton *)sender
{
    
    [self.coverView removeFromSuperview];
    
    
}







// 回车就结束编辑
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

// 当输入时让label消失
-(void)textViewDidBeginEditing:(UITextView *)textView
{
    [self.placeHoldLabel removeFromSuperview];
}






// 用户输入时
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
    [textField becomeFirstResponder];
    
    CGRect textFrame = textField.frame;
    CGPoint textPoint = [textField convertPoint:CGPointMake(0, textField.frame.size.height) toView:self.view];
    // 关键的一句，一定要转换
    int offset = textPoint.y + textFrame.size.height + 216 - self.view.frame.size.height + 64;
    // 24是textfield和键盘上方的间距，可以自由设定
    NSTimeInterval animationDuration = 0.30f;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    // 将视图的Y坐标向上移动offset个单位，以使下面腾出地方用于软键盘的显示
    if (offset > 0) {        self.coverView.frame = CGRectMake(0.0f, -offset, self.coverView.frame.size.width, self.coverView.frame.size.height);    }
    [UIView commitAnimations];
}
// 输入结束后，将视图恢复到原始状态
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    
    self.coverView.frame = CGRectMake(0, 0, self.coverView.frame.size.width, self.coverView.frame.size.height);
    return YES;
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}



// 点击底下弹出自定义时间生日的选择器的方法
- (void)selectTimeAction:(UIButton *)sender
{
  
    
    [self.coverView endEditing:YES];
    
    
    NSDate *date=[NSDate dateWithTimeIntervalSinceNow:9000000];
    self.coverView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.coverView1.backgroundColor = [UIColor blackColor];
    self.coverView1.alpha = 0.4;
    [[UIApplication sharedApplication].keyWindow addSubview:self.coverView1];
    
    _pickview =[[ZHPickView alloc] initDatePickWithDate:date datePickerMode:UIDatePickerModeDate isHaveNavControler:NO];
    [_pickview setToolbarTintColor:[UIColor whiteColor]];
    [_pickview setTintColor:[UIColor blackColor]];
    _pickview.delegate=self;
    [_pickview show];
    
}
// 当选择时间选择器确定后走的代理方法
-(void)toobarDonBtnHaveClick:(ZHPickView *)pickView resultString:(NSString *)resultString{
    
    [self.coverView1 removeFromSuperview];
    NSString *str = [resultString substringToIndex:10];
    [riLiBtn setTitle:str forState:UIControlStateNormal];
    

}

// 移除提醒的遮罩
- (void)remove:(NSNotification *)not
{
    [self.coverView1 removeFromSuperview];
}


// 弹出提醒选择时间的时间选择器
- (void)biaoAction:(UIButton *)sender
{
    

    
    NSLog(@"点了吗？");
    
    
    NSDate *now = [NSDate date];
    
    mydatePicker
    = [[UUDatePicker alloc]initWithframe:CGRectMake(0, HEIGHT - 200, WIDTH, 200)
                                Delegate:self
                             PickerStyle:UUDateStyle_YearMonthDayHourMinute];

    mydatePicker.ScrollToDate = now;

    
    SpecifiedTime.inputView = mydatePicker;
    

    [self.coverView addSubview:mydatePicker];
    
    
    
    shijianView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT - 240, WIDTH, 40)];
    shijianView.backgroundColor = RGBCOLOR(246, 248, 250);
    [self.coverView addSubview:shijianView];
    
    
    cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancleBtn.frame = CGRectMake(12, 0, 60, 40);
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [shijianView addSubview:cancleBtn];
    
    
    deteminBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    deteminBtn.frame = CGRectMake(WIDTH - 72, 0, 60, 40);
    [deteminBtn setTitle:@"确定" forState:UIControlStateNormal];
    [deteminBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [shijianView addSubview:deteminBtn];
    
    [cancleBtn addTarget:self action:@selector(cancleAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [deteminBtn addTarget:self action:@selector(deteminAction:) forControlEvents:UIControlEventTouchUpInside];
    
}









#pragma mark - UUDatePicker's delegate
- (void)uuDatePicker:(UUDatePicker *)datePicker
                year:(NSString *)year
               month:(NSString *)month
                 day:(NSString *)day
                hour:(NSString *)hour
              minute:(NSString *)minute
             weekDay:(NSString *)weekDay
{
    NSLog(@"这是什么");
 
    if (datePicker == mydatePicker) {
        [riLiBtn setTitle:[NSString stringWithFormat:@"%@-%@-%@",year,month,day] forState:UIControlStateNormal];
        [biaoBtn setTitle:[NSString stringWithFormat:@"%@:%@",hour,minute] forState:UIControlStateNormal];
    }else if (datePicker == daChedatePicker) {
        
        
        
        [yongcheTime setTitle:[NSString stringWithFormat:@"%@-%@-%@ %@:%@",year,month,day,hour,minute] forState:UIControlStateNormal];

        
        
    }
    
}


// 提醒的时间取消
- (void)cancleAction:(UIButton *)sender
{
    
    [shijianView removeFromSuperview];
    [mydatePicker removeFromSuperview];
    [daChedatePicker removeFromSuperview];
    [self.daCheprompView removeFromSuperview];
    [self.coverView1 removeFromSuperview];
    
}

// 提醒的时间确定
- (void)deteminAction:(UIButton *)sender
{
    
    
    [shijianView removeFromSuperview];
    [mydatePicker removeFromSuperview];
    [daChedatePicker removeFromSuperview];
    [self.daCheprompView removeFromSuperview];
     [self.coverView1 removeFromSuperview];
}


#pragma mark 录音
-(void)playVoice:(UIButton *)sender{
    
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
    [audioSession setActive:YES error:nil];
    
    //if (mp3FilePath != nil) {
        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[[[messageArry objectAtIndex:sender.tag]objectForKey:@"dataArry"]objectAtIndex:[sender.titleLabel.text intValue]]objectForKey:@"message"] error:nil];
    //}
    
    NSLog(@"%@mpp",mp3FilePath);
    [audioPlayer prepareToPlay];
    audioPlayer.volume = 1;
    [audioPlayer play];
    
    
    int  playDuration = (int)audioPlayer.duration;
    NSLog(@"音频时长为：%i",playDuration);



}
-(void)yuyinAction
{
        [self.view makeToast:@"向上滑动，取消发送" duration:1 position:@"center"];
    NSLog(@"开始录音");
    rTime=0;
    images.hidden=NO;
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(recordTimeTick) userInfo:nil repeats:YES];
    audioSession = [AVAudioSession sharedInstance];//得到AVAudioSession单例对象
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];//设置类别,表示该应用同时支持播放和录音
    [audioSession setActive:YES error:nil];//启动音频会话管理,此时会阻断后台音乐的播放.
    
    [audioRecorder prepareToRecord];
    [audioRecorder peakPowerForChannel:0.0];
    [audioRecorder record];

}




- (void)recordTimeTick {
    rTime += 1;
    if (rTime==60) {
        images.hidden=YES;
        [timer invalidate];

        [audioRecorder stop];                          //录音停止
        [audioSession setActive:NO error:nil];
        //[self transformCAFToMP3];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"录音超过60秒，分几段说吧~😊" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        
    }

}




-(void)yuyinStop
{
    NSLog(@"停止录音");
     images.hidden=YES;
    [timer invalidate];
    [audioRecorder stop];                          //录音停止
    [audioSession setActive:NO error:nil];         //一定要在录音停止以后再关闭音频会话管理（否则会报错），此时会延续后台音乐播放
    [self transformCAFToMP3];
    NSDictionary *dicc1=@{@"message":audioFileSavePath,@"type":@"voice",@"long":[NSString stringWithFormat:@"%d\"",rTime]};
    
    NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithDictionary:[messageArry objectAtIndex:messageArry.count-1]];
    
    NSMutableArray *arr=[NSMutableArray arrayWithArray:[dic objectForKey:@"dataArry"]];
    [arr addObject:dicc1];
    [dic setObject:arr forKey:@"dataArry"];
    [messageArry replaceObjectAtIndex:messageArry.count-1 withObject:dic];
    [tab reloadData];
    [tab scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:arr.count-1 inSection:messageArry.count-1] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

}
-(void)yuyinNo{
    NSLog(@"中途停止");
    images.hidden=YES;
    [timer invalidate];
    [audioRecorder stop];                          //录音停止
    [audioSession setActive:NO error:nil];
    
}


- (void)transformCAFToMP3 {
    mp3FilePath = [NSURL URLWithString:[NSTemporaryDirectory() stringByAppendingString:@"myselfRecord.mp3"]];
    
    @try {
        int read, write;
        
        FILE *pcm = fopen([[recordUrl absoluteString] cStringUsingEncoding:1], "rb");   //source 被转换的音频文件位置
        fseek(pcm, 4*1024, SEEK_CUR);                                                   //skip file header
        FILE *mp3 = fopen([[mp3FilePath absoluteString] cStringUsingEncoding:1], "wb"); //output 输出生成的Mp3文件位置
        
        const int PCM_SIZE = 8192;
        const int MP3_SIZE = 8192;
        short int pcm_buffer[PCM_SIZE*2];
        unsigned char mp3_buffer[MP3_SIZE];
        
        lame_t lame = lame_init();
        lame_set_in_samplerate(lame, 11025.0);
        lame_set_VBR(lame, vbr_default);
        lame_init_params(lame);
        
        do {
            read = fread(pcm_buffer, 2*sizeof(short int), PCM_SIZE, pcm);
            if (read == 0)
                write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);
            else
                write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE);
            
            fwrite(mp3_buffer, write, 1, mp3);
            
        } while (read != 0);
        
        lame_close(lame);
        fclose(mp3);
        fclose(pcm);
    }
    @catch (NSException *exception) {
        NSLog(@"%@",[exception description]);
    }
    @finally {
        audioFileSavePath = mp3FilePath;
        //        NSLog(@"MP3生成成功: %@",audioFileSavePath);
        //        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"mp3转化成功！" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        //        [alert show];
    }
}

// 订咖啡
-(void)bangKaFei
{
    
    
    
    
    openArr = [NSMutableArray arrayWithObjects:@"0",@"0",@"0", nil];
    beishu = 0;
    yuanshu = 0;
    NSArray *listArr = @[@[@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"27",@"19",@"16"] mutableCopy]},@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"26",@"18",@"9"] mutableCopy]},@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"25",@"22",@"19"] mutableCopy]}],@[@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"15",@"11",@"3"] mutableCopy]},@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"33",@"26",@"21"] mutableCopy]},@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"24",@"22",@"18"] mutableCopy]}],@[@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"23",@"22",@"21"] mutableCopy]},@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"22",@"18",@"16"] mutableCopy]},@{@"name":@"拿铁",@"num":[@[@"0",@"0",@"0"] mutableCopy],@"price":[@[@"15",@"13",@"11"] mutableCopy]}]];
    
    
    kafeiArr = [NSMutableArray arrayWithArray:listArr];
    
    
    
    
    
    
    
    
    
    NSLog(@"我要定咖啡啊");
    
    self.coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.coverView.backgroundColor = [UIColor clearColor];
    [[UIApplication sharedApplication].keyWindow addSubview:self.coverView];
    UIView *alphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.coverView.frame.size.width, self.coverView.frame.size.height)];
    alphaView.backgroundColor = [UIColor blackColor];
    alphaView.alpha = 0.4;
    [self.coverView addSubview:alphaView];
    
    self.promptView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT / 4, WIDTH, HEIGHT / 4 * 3)];;
    self.promptView.backgroundColor = RGBCOLOR(255.0, 255.0, 255.0);

    [self.coverView addSubview:self.promptView];
    
    
    UIView *fBGView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 42)];
    fBGView.backgroundColor = RGBCOLOR(246, 248, 250);
    [self.promptView addSubview:fBGView];
    
    UILabel *tixingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 14, 70, 14)];
    tixingLabel.text = @"星巴克";
    tixingLabel.font = [UIFont systemFontOfSize:14];
    tixingLabel.textColor = RGBCOLOR(32, 32, 32);
    [fBGView addSubview:tixingLabel];
    
    UIButton *quedingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quedingBtn.frame = CGRectMake(WIDTH - 60, 14, 60, 14);
    [quedingBtn setTitle:@"确定" forState:UIControlStateNormal];
    [quedingBtn setTitleColor:RGBCOLOR(255, 109, 109) forState:UIControlStateNormal];
    quedingBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [quedingBtn addTarget:self action:@selector(quedingkafeiAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [fBGView addSubview:quedingBtn];
    
    
    UIButton *quxiaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quxiaoBtn.frame = CGRectMake(WIDTH - 120, 14, 60, 14);
    [quxiaoBtn setTitle:@"取消" forState:UIControlStateNormal];
    [quxiaoBtn setTitleColor:RGBCOLOR(144, 144, 144) forState:UIControlStateNormal];
    quxiaoBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [quxiaoBtn addTarget:self action:@selector(quxiaokafeiAction:) forControlEvents:UIControlEventTouchUpInside];
    [fBGView addSubview:quxiaoBtn];

    
    self.kafeiTab = [[UITableView alloc] initWithFrame:CGRectMake(0, 42, WIDTH, CGRectGetHeight(self.promptView.frame) - 102) style:UITableViewStyleGrouped];
    
    self.kafeiTab.delegate = self;
    self.kafeiTab.dataSource = self;
    [self.promptView addSubview:self.kafeiTab];
    
    
    
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.promptView.frame) - 60, WIDTH, 60)];
    bottomView.backgroundColor = RGBCOLOR(246, 248, 250);
    [self.promptView addSubview:bottomView];
    
    UILabel *alllabel1 = [[UILabel alloc] initWithFrame:CGRectMake(15, 13, 40, 14)];
    alllabel1.text = @"总共:";
    alllabel1.font = [UIFont systemFontOfSize:14];
    alllabel1.textColor = RGBCOLOR(69, 69, 69);
    [bottomView addSubview:alllabel1];
    
    
    UILabel *alllabel2 = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(alllabel1.frame) + 11, 40, 14)];
    alllabel2.text = @"总共:";
    alllabel2.font = [UIFont systemFontOfSize:14];
    alllabel2.textColor = RGBCOLOR(69, 69, 69);
    [bottomView addSubview:alllabel2];
    
    
    beiNum = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(alllabel1.frame) + 10, 13, 28, 14)];
    beiNum.text = @"0";
    beiNum.font = [UIFont systemFontOfSize:14];
    beiNum.textColor = RGBCOLOR(255, 109, 109);
    beiNum.textAlignment = NSTextAlignmentRight;
    [bottomView addSubview:beiNum];
    
    
    yuanNum = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(alllabel1.frame) + 10, CGRectGetMaxY(alllabel1.frame) + 11, 28, 14)];
    yuanNum.text = @"0";
    yuanNum.font = [UIFont systemFontOfSize:14];
    yuanNum.textColor = RGBCOLOR(255, 109, 109);
    yuanNum.textAlignment = NSTextAlignmentRight;
    [bottomView addSubview:yuanNum];
    
    
    UILabel *bei = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(beiNum.frame) + 1, 13, 14, 14)];
    bei.text = @"杯";
    bei.font = [UIFont systemFontOfSize:14];
    bei.textColor = RGBCOLOR(69, 69, 69);
    [bottomView addSubview:bei];
    
    UILabel *yuan = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(beiNum.frame) + 1, CGRectGetMaxY(alllabel1.frame) + 11, 14, 14)];
    yuan.text = @"元";
    yuan.font = [UIFont systemFontOfSize:14];
    yuan.textColor = RGBCOLOR(69, 69, 69);
    [bottomView addSubview:yuan];

    
    
    
}


// 咖啡选择界面的取消和确定

- (void)quedingkafeiAction:(UIButton *)sender
{
    
    [self.coverView removeFromSuperview];
    
}


- (void)quxiaokafeiAction:(UIButton *)sender
{
    
    [self.coverView removeFromSuperview];
    
}



// 打车出来的选择

-(void)bangYaoDache
{
    
    self.coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.coverView.backgroundColor = [UIColor clearColor];
    [[UIApplication sharedApplication].keyWindow addSubview:self.coverView];
    UIView *alphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.coverView.frame.size.width, self.coverView.frame.size.height)];
    alphaView.backgroundColor = [UIColor blackColor];
    alphaView.alpha = 0.4;
    [self.coverView addSubview:alphaView];
    
    self.promptView = [[UIView alloc] initWithFrame:CGRectMake(40, HEIGHT / 4, WIDTH - 80, 200)];;
    self.promptView.backgroundColor = RGBCOLOR(255.0, 255.0, 255.0);
    self.promptView.layer.cornerRadius = 5;
    self.promptView.layer.masksToBounds = YES;
    [self.coverView addSubview:self.promptView];
    
    
    UIView *fBGView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 80, 40)];
    fBGView.backgroundColor = RGBCOLOR(255, 109, 109);
    [self.promptView addSubview:fBGView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(fBGView.frame) / 2 - 40, 12, 80, 16)];
    
    titleLabel.text = @"打车";
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor whiteColor];
    
    [fBGView addSubview:titleLabel];
    
    
    UILabel *qidian = [[UILabel alloc] initWithFrame:CGRectMake(21, CGRectGetMaxY(fBGView.frame) + 13, 70, 14)];
    qidian.textColor = RGBCOLOR(70, 70, 70);
    qidian.font = [UIFont boldSystemFontOfSize:14];
    qidian.text = @"起点";
    [self.promptView addSubview:qidian];
    
    
    UITextField *qidianTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(qidian.frame) + 20, CGRectGetMinY(qidian.frame), CGRectGetWidth(self.promptView.frame) - CGRectGetMaxX(qidian.frame) - 40, CGRectGetHeight(qidian.frame))];
    qidianTF.placeholder = @"请输入起点";
    qidianTF.font = [UIFont systemFontOfSize:14];
    qidianTF.delegate = self;
    [self.promptView addSubview:qidianTF];
    
    UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 80, CGRectGetWidth(self.promptView.frame), 1)];
    topLine.backgroundColor = RGBCOLOR(230, 230, 230);
    [self.promptView addSubview:topLine];
    
    
    UILabel *zhongdian = [[UILabel alloc] initWithFrame:CGRectMake(21, CGRectGetMaxY(fBGView.frame) + 53, 70, 14)];
    zhongdian.textColor = RGBCOLOR(70, 70, 70);
    zhongdian.font = [UIFont boldSystemFontOfSize:14];
    zhongdian.text = @"终点";
    [self.promptView addSubview:zhongdian];
    
    
    UITextField *zhongdianTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(qidian.frame) + 20, CGRectGetMinY(zhongdian.frame), CGRectGetWidth(self.promptView.frame) - CGRectGetMaxX(qidian.frame) - 40, CGRectGetHeight(qidian.frame))];
    zhongdianTF.placeholder = @"请输入终点";
    zhongdianTF.font = [UIFont systemFontOfSize:14];
    zhongdianTF.delegate = self;
    [self.promptView addSubview:zhongdianTF];
    
    UIView *zhongdianLine = [[UIView alloc] initWithFrame:CGRectMake(0, 120, CGRectGetWidth(self.promptView.frame), 1)];
    zhongdianLine.backgroundColor = RGBCOLOR(230, 230, 230);
    [self.promptView addSubview:zhongdianLine];
    
    
    
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(21, CGRectGetMaxY(fBGView.frame) + 93, 70, 14)];
    timeLabel.textColor = RGBCOLOR(70, 70, 70);
    timeLabel.font = [UIFont boldSystemFontOfSize:14];
    timeLabel.text = @"用车时间";
    [self.promptView addSubview:timeLabel];
    
    
    yongcheTime = [UIButton buttonWithType:UIButtonTypeCustom];
    yongcheTime.frame = CGRectMake(CGRectGetMaxX(qidian.frame) + 20, CGRectGetMinY(timeLabel.frame), CGRectGetWidth(self.promptView.frame) - CGRectGetMaxX(qidian.frame) - 40, CGRectGetHeight(qidian.frame));
    [yongcheTime setTitle:@"请选择用车时间" forState:UIControlStateNormal];
    [yongcheTime setTitleColor:RGBCOLOR(50, 50, 50) forState:UIControlStateNormal];
    yongcheTime.titleLabel.font = [UIFont systemFontOfSize:14];
    [yongcheTime addTarget:self action:@selector(yongcheTimeAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.promptView addSubview:yongcheTime];
    
    
    UIButton *quxiaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quxiaoBtn.frame = CGRectMake(0, 160, CGRectGetWidth(self.promptView.frame) / 2, 40);
    quxiaoBtn.backgroundColor = RGBCOLOR(231, 231, 231);
    [quxiaoBtn setTitleColor:RGBCOLOR(144, 144, 144) forState:UIControlStateNormal];
    [quxiaoBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self.promptView addSubview:quxiaoBtn];
    
    
    UIButton *quedingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quedingBtn.frame = CGRectMake(CGRectGetWidth(quxiaoBtn.frame), 160, CGRectGetWidth(self.promptView.frame) / 2, 40);
    quedingBtn.backgroundColor = RGBCOLOR(255, 109, 109);
    [quedingBtn setTitleColor:RGBCOLOR(255, 255, 255) forState:UIControlStateNormal];
    [quedingBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self.promptView addSubview:quedingBtn];
    
    [quxiaoBtn addTarget:self action:@selector(yongcheCancleAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [quedingBtn addTarget:self action:@selector(yongcheDeteminAction:) forControlEvents:UIControlEventTouchUpInside];
}




- (void)yongcheTimeAction:(UIButton *)sender
{
    
    
    
    
    
    
    self.coverView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.coverView1.backgroundColor = [UIColor clearColor];
    [self.coverView addSubview:self.coverView1];
    
    
    self.daCheprompView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT - 200, WIDTH, 200)];;
    self.daCheprompView.backgroundColor = RGBCOLOR(255.0, 255.0, 255.0);
    [self.coverView1 addSubview:self.daCheprompView];
    
    
    
    
    
    NSDate *now = [NSDate date];
    

    daChedatePicker
    = [[UUDatePicker alloc]initWithframe:CGRectMake(0, 0, WIDTH, 200)
                                Delegate:self
                             PickerStyle:UUDateStyle_YearMonthDayHourMinute];
    
    daChedatePicker.ScrollToDate = now;
    
    
    SpecifiedTime.inputView = daChedatePicker;
    
    [self.daCheprompView addSubview:daChedatePicker];
    
    
    
    shijianView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT - 240, WIDTH, 40)];
    shijianView.backgroundColor = RGBCOLOR(246, 248, 250);
    [self.coverView1 addSubview:shijianView];
    
    
    cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancleBtn.frame = CGRectMake(12, 0, 60, 40);
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [shijianView addSubview:cancleBtn];
    
    
    deteminBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    deteminBtn.frame = CGRectMake(WIDTH - 72, 0, 60, 40);
    [deteminBtn setTitle:@"确定" forState:UIControlStateNormal];
    [deteminBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [shijianView addSubview:deteminBtn];
    
    [cancleBtn addTarget:self action:@selector(cancleAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [deteminBtn addTarget:self action:@selector(deteminAction:) forControlEvents:UIControlEventTouchUpInside];

    
    
    

    
    
}


// 用车取消
- (void)yongcheCancleAction:(UIButton *)sender
{
    
    [self.coverView removeFromSuperview];
    
    
}




// 用车确定

- (void)yongcheDeteminAction:(UIButton *)sender
{
    
    [self.coverView removeFromSuperview];
    
    
}


#pragma -mark 咖啡选择的加减方法
- (void)addDa:(UIButton *)sender
{
    
    
    beishu = beishu + 1;
    
    NSString *num = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] objectAtIndex:0];
    
    NSInteger addnum = [num integerValue];
    
    
    
    
    
    
    addnum = addnum + 1;
    
    NSString *newNum = [NSString stringWithFormat:@"%ld",addnum];
    
    [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] replaceObjectAtIndex:0 withObject:newNum];
    
    [self.kafeiTab reloadData];
    
    beiNum.text = [NSString stringWithFormat:@"%ld",beishu];
    
    
    
    NSString *yuan = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"price"] objectAtIndex:0];
    
    NSInteger addyuan = [yuan integerValue];
    yuanshu = yuanshu + addyuan;
    yuanNum.text = [NSString stringWithFormat:@"%ld",yuanshu];
    
    
}

- (void)addZhong:(UIButton *)sender
{
    
    beishu = beishu + 1;
    
    NSString *num = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] objectAtIndex:1];
    
    NSInteger addnum = [num integerValue];
    
    addnum = addnum + 1;
    
    NSString *newNum = [NSString stringWithFormat:@"%ld",addnum];
    
    [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] replaceObjectAtIndex:1 withObject:newNum];
    
    [self.kafeiTab reloadData];
    
    beiNum.text = [NSString stringWithFormat:@"%ld",beishu];
    NSString *yuan = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"price"] objectAtIndex:1];
    
    NSInteger addyuan = [yuan integerValue];
    yuanshu = yuanshu + addyuan;
    yuanNum.text = [NSString stringWithFormat:@"%ld",yuanshu];
}


- (void)addXiao:(UIButton *)sender
{
    
    
    beishu = beishu + 1;
    
    NSString *num = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] objectAtIndex:2];
    
    NSInteger addnum = [num integerValue];
    
    addnum = addnum + 1;
    
    NSString *newNum = [NSString stringWithFormat:@"%ld",addnum];
    
    [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] replaceObjectAtIndex:2 withObject:newNum];
    
    [self.kafeiTab reloadData];
    
    beiNum.text = [NSString stringWithFormat:@"%ld",beishu];
    NSString *yuan = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"price"] objectAtIndex:2];
    
    NSInteger addyuan = [yuan integerValue];
    yuanshu = yuanshu + addyuan;
    yuanNum.text = [NSString stringWithFormat:@"%ld",yuanshu];
}


- (void)jianDa:(UIButton *)sender
{
    
    
    
    
    
    NSString *num = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] objectAtIndex:0];
    
    NSInteger addnum = [num integerValue];
    
    
    if (addnum > 0) {
        addnum = addnum - 1;
        
        beishu = beishu - 1;
        
        NSString *yuan = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"price"] objectAtIndex:0];
        
        NSInteger addyuan = [yuan integerValue];
        yuanshu = yuanshu - addyuan;
        yuanNum.text = [NSString stringWithFormat:@"%ld",yuanshu];
        
        
    }
    
    
    
    NSString *newNum = [NSString stringWithFormat:@"%ld",addnum];
    
    [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] replaceObjectAtIndex:0 withObject:newNum];
    
    [self.kafeiTab reloadData];
    
    beiNum.text = [NSString stringWithFormat:@"%ld",beishu];
    
    
}



- (void)jianZhong:(UIButton *)sender
{
    
    
    
    
    NSString *num = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] objectAtIndex:1];
    
    NSInteger addnum = [num integerValue];
    
    if (addnum > 0) {
        addnum = addnum - 1;
        
        beishu = beishu - 1;
        NSString *yuan = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"price"] objectAtIndex:1];
        
        NSInteger addyuan = [yuan integerValue];
        yuanshu = yuanshu - addyuan;
        yuanNum.text = [NSString stringWithFormat:@"%ld",yuanshu];
        
    }
    
    NSString *newNum = [NSString stringWithFormat:@"%ld",addnum];
    
    [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] replaceObjectAtIndex:1 withObject:newNum];
    
    [self.kafeiTab reloadData];
    
    beiNum.text = [NSString stringWithFormat:@"%ld",beishu];
    
    
    
}

- (void)jianXiao:(UIButton *)sender
{
    
    
    
    
    NSString *num = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] objectAtIndex:2];
    
    NSInteger addnum = [num integerValue];
    
    if (addnum > 0) {
        addnum = addnum - 1;
        
        beishu = beishu - 1;
        NSString *yuan = [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"price"] objectAtIndex:2];
        
        NSInteger addyuan = [yuan integerValue];
        yuanshu = yuanshu - addyuan;
        yuanNum.text = [NSString stringWithFormat:@"%ld",yuanshu];
    }
    
    NSString *newNum = [NSString stringWithFormat:@"%ld",addnum];
    
    [[[[kafeiArr objectAtIndex:sender.tag / 100] objectAtIndex:sender.tag % 10] objectForKey:@"num"] replaceObjectAtIndex:2 withObject:newNum];
    
    [self.kafeiTab reloadData];
    
    beiNum.text = [NSString stringWithFormat:@"%ld",beishu];
    
    
    
}


@end
